package org.crazyit.activiti_d2._2_Register;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;

import java.util.Map;

public class Register {

    public static void main(String[] args) {

        //1. 读取自定义配置
        ProcessEngineConfiguration config = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-context_1.xml");

        /**
         * 2. 创建ProcessEngine 实例
         * 默认情况下, 创建的ProcessEngine 名称为"default", 如果需要设置名称, 则可调用引擎配置类的setProcessEngineName() 方法
         */
        config.setProcessEngineName("engine1");
        ProcessEngine engine = config.buildProcessEngine();

        //3. 获取ProcessEngine 的Map
        Map<String, ProcessEngine> engines = ProcessEngines.getProcessEngines();
        for (Map.Entry<String, ProcessEngine> entry : engines.entrySet()) {
            System.out.println("engine 名:" + entry.getKey());
            System.out.println("engine 实例:" + entry.getValue());
        }
        System.out.println("注册后引擎数:" + engines.size());

        /**
         * 4. 注销ProcessEngine 实例
         * 该方法只是单纯地将ProcessEngine 实例从Map 中移除, 并不会调用ProcessEngine 的close 方法
         */
        ProcessEngines.unregister(engine);
        System.out.println("调用unregister 后引擎数:" + engines.size());

    }

}
